<?php
namespace pfp {
use pfp\lib as pfpLib;

/** TEMP NOTES:
     * 
     * regex:
     * "/^$/"         empty string
     * "/^[\s]*$/"    empty string + whitespace
     * "/.*?/"        Anything/Everything + empty string + whitespace
     * "//"
     * 
     * Simple regex

        Regex quick reference
        [abc]     A single character: a, b or c
        [^abc]     Any single character but a, b, or c
        [a-z]     Any single character in the range a-z
        [a-zA-Z]     Any single character in the range a-z or A-Z
        ^     Start of line
        $     End of line
        \A     Start of string
        \z     End of string
        .     Any single character
        \s     Any whitespace character
        \S     Any non-whitespace character
        \d     Any digit
        \D     Any non-digit
        \w     Any word character (letter, number, underscore)
        \W     Any non-word character
        \b     Any word boundary character
        (...)     Capture everything enclosed
        (a|b)     a or b
        a?     Zero or one of a
        a*     Zero or more of a
        a+     One or more of a
        a{3}     Exactly 3 of a
        a{3,}     3 or more of a
        a{3,6}     Between 3 and 6 of a

        options: i case insensitive m make dot match newlines x ignore whitespace in regex o perform #{...} substitutions only once
     * 
     * 
     * 
     * 
     */

/**
 * Description of pfp index ( entry point )
 * 
 * @author George Zeakis<zeageorge@google.com>
 * 
 * @todo WebSockets, WebWorkers
 * 
 * 
 * 
 */

    \define('_JEXEC', '1');
    $pfp_entry_point = \dirname(__FILE__) . \DIRECTORY_SEPARATOR;

    \ob_start();

    require_once $pfp_entry_point.
            'pfp'.      \DIRECTORY_SEPARATOR.
            'protected'.\DIRECTORY_SEPARATOR.
            'pfp_libs'. \DIRECTORY_SEPARATOR.
            'Watcher.php';
    
    $watcher = pfpLib\Watcher::getInstance(); \register_tick_function(array($watcher,'act'));

    declare(ticks=1){
        try{
            require_once $pfp_entry_point.
                    'pfp'.      \DIRECTORY_SEPARATOR.
                    'protected'.\DIRECTORY_SEPARATOR.
                    'pfp_libs'. \DIRECTORY_SEPARATOR.
                    'Autoloader.php';
            pfpLib\Autoloader::Init();
            pfpLib\Autoloader::registerNamespace("pfp\\",      $pfp_entry_point."pfp".\DIRECTORY_SEPARATOR);
            pfpLib\Autoloader::registerNamespace("pfp\\lib\\", $pfp_entry_point."pfp".
                    \DIRECTORY_SEPARATOR."protected".
                    \DIRECTORY_SEPARATOR."pfp_libs".
                    \DIRECTORY_SEPARATOR);
                    
//            $t = new pfpLib\test();
//            die();
            
            $conf = new pfpLib\Config($pfp_entry_point.
                    'pfp'.      \DIRECTORY_SEPARATOR.
                    'protected'.\DIRECTORY_SEPARATOR.
                    'pfp_config_file.php', $pfp_entry_point);
            
            unset($pfp_entry_point); 

            $pfp = new pfpLib\pfp($conf);

        } catch (pfpLib\codeExecution_FlowControlException $exc) {
            echo "<pre>";
            echo "".$exc->getMessage()
                    ."<br />\n";
//            if ($conf instanceof Config){
//                if (isset($conf->pfp->inDebugMode) && $conf->pfp->inDebugMode()===TRUE){
//                    $errors = array(
//                            "0"=>array(
//                                "error_type"=>"Exception",
//                                "exception_category"     =>"Server Error",
//                                "exception_number"       =>"0x000200",
//                                "exception_msg"          =>$exc->getMessage(),
//                                "exception_code"         =>$exc->getCode(),
//                                "exception_file"         =>$exc->getFile(),
//                                "exception_line"         =>$exc->getLine(),
//                                "exception_trace"        =>$exc->getTrace(),
//                                "exception_traceAsString"=>$exc->getTraceAsString(),
//                            ),
//                    );
//                    $r2c = new responseToClient(array("responce"=>"-1", "errors"=>$errors));
//                    $r2c->send();
//                    die();
//                } else { // production mode !!!
//                    $errors = array(
//                        "0"=>array(
//                            "error_type"             =>"Exception",
//                            "exception_category"     =>"Server Error",
//                            "exception_number"       =>"0x000300",
//    //                            "exception_msg"          =>$exc->getMessage(),
//                        ),
//                    );
//                    header('Content-type: application/json');
//                    echo json_encode(array("responce"=>"-1", "errors"=>$errors));
//                    die();
//                }
//            } else {
//                $errors = array(
//                    "0"=>array(
//                        "error_type"             =>"Exception",
//                        "exception_category"     =>"Server Error",
//                        "exception_number"       =>"0x001000",
//    //                        "exception_msg"          =>$exc->getMessage(),
//                    ),
//                );
//                header('Content-type: application/json');
//                echo json_encode(array("responce"=>"-1", "errors"=>$errors));
//                die();
//            }
        }
    }
}
?>